package com.tansun.easycare.rule.deployonline.service.impl;

import java.io.File;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.tansun.easycare.core.config.Global;
import com.tansun.easycare.rule.common.Constant;
import com.tansun.easycare.rule.common.service.impl.RuleBaseServiceImpl;
import com.tansun.easycare.rule.datamodel.dao.RuleDatasetDao;
import com.tansun.easycare.rule.datamodel.entity.RuleDataparams;
import com.tansun.easycare.rule.datamodel.entity.RuleDataset;
import com.tansun.easycare.rule.datamodel.model.Attribute;
import com.tansun.easycare.rule.datamodel.model.DataModel;
import com.tansun.easycare.rule.datamodel.service.RuleDataparamsService;
import com.tansun.easycare.rule.deployonline.dao.ReflactDataDao;
import com.tansun.easycare.rule.deployonline.dao.RuleDeploymentDao;
import com.tansun.easycare.rule.deployonline.entity.ReflactData;
import com.tansun.easycare.rule.deployonline.entity.RuleDataInfo;
import com.tansun.easycare.rule.deployonline.entity.RuleDeployment;
import com.tansun.easycare.rule.deployonline.entity.RuleEnterpoint;
import com.tansun.easycare.rule.deployonline.model.Deployment;
import com.tansun.easycare.rule.deployonline.model.EnterPoint;
import com.tansun.easycare.rule.deployonline.model.ReflactDataVO;
import com.tansun.easycare.rule.deployonline.model.RuleDeployVO;
import com.tansun.easycare.rule.deployonline.service.RuleDeployOnlineService;
import com.tansun.easycare.rule.deployonline.service.RuleEnterpointService;
import com.tansun.easycare.rule.exception.BizException;
import com.tansun.easycare.rule.referencedata.entity.RuleReferenceData;
import com.tansun.easycare.rule.referencedata.service.RuleReferenceDataService;
import com.tansun.easycare.rule.ruleflow.service.RuleFlowService;
import com.tansun.easycare.rule.rulemange.entity.RuleManage;
import com.tansun.easycare.rule.rulemange.service.RuleManageService;
import com.tansun.easycare.rule.ruleversion.entity.RuleVersioninfo;
import com.tansun.easycare.rule.ruleversion.service.RuleVersioninfoService;
import com.tansun.easycare.rule.utils.ClassChangeUtils;
import com.tansun.easycare.rule.utils.ObjectXmlTool;
import com.tansun.rule.common.RuleModelTypeEnum;
import com.tansun.rule.sparkCode.entity.deployline.RuleVersionVO;
import com.tansun.rule.utils.JavaUnmarshaller;
import com.tansun.rule.utils.ZipUtils;
import com.tansun.ruledata.data.service.BussinessSynchService;



@SuppressWarnings("deprecation")
@Service
public class RuleDeployOnlineServiceImpl extends RuleBaseServiceImpl<RuleDeploymentDao, RuleDeployment> implements RuleDeployOnlineService {

	private SimpleDateFormat spf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	private SimpleDateFormat spf2 = new SimpleDateFormat("yyyyMMddHHmmss");
	
	private static String modelDir = "/deployOnline";
	private static String deployFile = "/deploy.xml";
	@Autowired
	private  RuleEnterpointService  ruleEnterpointService;
	
	@Autowired
	private  RuleFlowService   ruleFlowService;
	@Autowired
	private  RuleDatasetDao   ruleDatasetDao;
	
	@Autowired
	private  ReflactDataDao  reflactDataDao;
	
	@Autowired
	private  RuleDataparamsService  ruleDataparamsService;
	
	@Autowired
	private  RuleVersioninfoService  ruleVersioninfoService;
	
	@Autowired
	private  ObjectXmlTool xmlTool;
	@Autowired
	private RuleReferenceDataService ruleReferenceDataService;
    @Autowired
    private RuleManageService ruleManageService;
    @Autowired
    private RuleDeploymentDao ruleDeploymentDao;
	@Autowired
	private BussinessSynchService bussinessSynchService;
	
	@Override
	public void saveOrUpdate(RuleDeployVO ruleDeploy) throws BizException {
		RuleDeployment deployment = ruleDeploy.getRuleDeployment();
        if (StringUtils.isEmpty(deployment.getDeployCode())){
        	String type = RuleModelTypeEnum.getType(RuleModelTypeEnum.Deploy.code);
        	deployment.setDeployCode(super.generalCodeByType(type, deployment.getProjectCode()));
        }
		this.save(deployment);
		
		List<RuleEnterpoint> enterList = ruleDeploy.getEnterpointList();
		for (RuleEnterpoint ruleEnterpoint :enterList){
			RuleEnterpoint re = new RuleEnterpoint();
			re.setId(ruleEnterpoint.getId());
			RuleEnterpoint ago = this.ruleEnterpointService.get(re);
			if(ago!=null) {
				ReflactData reflactData = new ReflactData();
				reflactData.setEnterPonit(ago.getCode());
				reflactData.setProjectCode(deployment.getProjectCode());
				String enterPonit = ruleEnterpoint.getCode();
				if(StringUtils.isNotEmpty(enterPonit)) {
					List<ReflactData> reflactDataList = reflactDataDao.findList(reflactData);
					for(ReflactData rd:reflactDataList) {
						if(!enterPonit.equals(rd.getEnterPonit())) {
							rd.setEnterPonit(enterPonit);
							reflactDataDao.update(rd);
						}
					}
				}else {
					reflactDataDao.delete(reflactData);
				}
			}
			String  ruleFlowId  = ruleEnterpoint.getRuleflowId();
			if (ruleFlowId !=null) {
				String[]  args =StringUtils.split(ruleFlowId, "_");
				if (args !=null && args.length>0) {
					ruleEnterpoint.setRuleflowId(args[0]);
				}
			}
			ruleEnterpoint.setProjectCode(deployment.getProjectCode());
			ruleEnterpoint.setDeploymentId(deployment.getId());
			this.ruleEnterpointService.save(ruleEnterpoint);
			ruleEnterpoint.getId();
		}
		
		RuleEnterpoint searchEnterpoint = new RuleEnterpoint();
		searchEnterpoint.setDeploymentId(deployment.getId());
		List<RuleEnterpoint> list = this.ruleEnterpointService.findList(searchEnterpoint);
		for(RuleEnterpoint ruleEnter:list) {
			boolean contain = false;
			for(RuleEnterpoint ruleEnterpoint :enterList) {
				if(ruleEnterpoint.getId().equals(ruleEnter.getId())) {
					contain = true;
					break;
				}
			}
			if(!contain) {
				this.ruleEnterpointService.delete(ruleEnter);
			}

		}
	}

	@Override
	public RuleDeployVO findRuleDeploy(String id) throws BizException {
		RuleDeployVO ruleDeployVO  = new  RuleDeployVO();
		RuleDeployment ruleDeployment = this.get(id);
		ruleDeployVO.setRuleDeployment(ruleDeployment);
		RuleEnterpoint  enterpoint  = new  RuleEnterpoint();
		enterpoint.setDeploymentId(id);
		ruleDeployVO.setEnterpointList(this.ruleEnterpointService.findList(enterpoint));
		return ruleDeployVO;
	}

	@Override
	public void deleteRuleDeploy(String id) throws BizException {
		RuleDeployment  ruleDeployment = this.get(id);
		RuleEnterpoint  ruleEnterpoint = new RuleEnterpoint();
		ruleEnterpoint.setDeploymentId(ruleDeployment.getId());
		List<RuleEnterpoint> list = this.ruleEnterpointService.findList(ruleEnterpoint);
		for (RuleEnterpoint ruleEnter :list){
			this.ruleEnterpointService.delete(ruleEnter);
		}
		this.delete(ruleDeployment);
		
	}
	@Override
	public void createRulePackage(String deployCode, String userName,String  projectCode) throws Exception {
		StringBuffer logStrbuf = new StringBuffer("\n\n\n");
		logStrbuf.append("***新规则打包任务***\n");
		logStrbuf.append("生成规则包时间:"+spf.format(new Date())+"\n");
		logStrbuf.append("执行人:"+userName+"\n");
		int fileCount=0;
		
		String  deployDir =Global.getConfig("DeployFileDir");
		String path = deployDir +"/"+projectCode;
		RuleDeployment deployment = this.get(deployCode);
		String deploypath = path+modelDir+"/"+deployment.getDeployCode();
		String drlBasePath  = deploypath+"/packageDir/com/tansun";
		File packageDir = new File(drlBasePath);
		if(packageDir.exists()){
			//备份历史包信息
			File rulePackageF = new File(deploypath+"/rulePackage.jar");
			File bakDir = new File(deploypath+"/_"+spf2.format(new Date()));
			FileUtils.copyDirectory(new File(deploypath+"/packageDir"), bakDir);
			FileUtils.copyFileToDirectory(rulePackageF, bakDir, true);
			logStrbuf.append("备份历史包数据:"+spf.format(new Date())+"\n");
			rulePackageF.delete();
			
			deleteDir(packageDir);
			//
		}
		packageDir.mkdirs();
		logStrbuf.append("规则Drl包文件列表:\n");
		  
		
		RuleEnterpoint  enterInfo  = new  RuleEnterpoint();
		enterInfo.setDeploymentId(deployment.getId());
		List<RuleEnterpoint> enterPoints =  this.ruleEnterpointService.findList(enterInfo) ;
	
		Deployment  depm = new  Deployment();
		BeanUtils.copyProperties(depm, deployment);
		depm.setUsername(deployment.getUserName());
		depm.setTarget(deployment.getServerUrl());
		depm.setProjectName(projectCode);
		depm.setProjectZhName(deployment.getDeployName());
		
		String  fileName =null;
		String  drlPath = null;
		EnterPoint enPoint = null;
		List<RuleVersionVO> ruleVersions = new ArrayList<RuleVersionVO>();
		for (RuleEnterpoint enterPoint : enterPoints) {
			enPoint = new  EnterPoint();
			BeanUtils.copyProperties(enPoint, enterPoint);
			enPoint.setDesc(enterPoint.getDescription());
			depm.getEnterPoint().add(enPoint);
			RuleManage rulemanage = ruleManageService.findByCode(enterPoint.getRuleflowId(), projectCode);
//			String[] ruleflowinfo = enterPoint.getRuleflowId().split("_");
			List<RuleVersioninfo> flowVersions =this.ruleFlowService.findRuleFlowPublishVersion(projectCode,enterPoint.getRuleflowId(), rulemanage.getActiveVersion());
//			Map<String,String> className_code_map = new HashMap<String,String>();
			for (RuleVersioninfo flowVersion:flowVersions){
				RuleVersionVO ruleVersionVO = ClassChangeUtils.changeClass(flowVersion);
				ruleVersions.add(ruleVersionVO);
			    fileName = flowVersion.getModelCode()+"_"+flowVersion.getVersion();
			    if (flowVersion.getModelType().equals(RuleModelTypeEnum.RuleFlow.code)){
			    	fileName = fileName +".bpmn";
			    }else if (flowVersion.getModelType().equals(RuleModelTypeEnum.ExecutionBlock.code)){
			    	fileName = fileName +".bpmn";
			    }
			    else {
			    	fileName = fileName +".drl";
			    }
			    drlPath = drlBasePath+File.separator+fileName;
			    fileCount++;
			    com.tansun.easycare.rule.common.FileUtils.writeFileDrl(flowVersion.getRuleContent().getBytes(), drlPath);
			}
		}
		RuleVersioninfo  verInfo  = new  RuleVersioninfo();
		verInfo.setProjectCode(projectCode);
		verInfo.setManageId("func_"+projectCode);
		List<RuleVersioninfo> flist =this.ruleVersioninfoService.findList(verInfo);
		if (flist != null && flist.size()>0){
			RuleVersioninfo flowVersion = flist.get(0);
			RuleVersionVO ruleVersionVO = ClassChangeUtils.changeClass(flowVersion);
			ruleVersions.add(ruleVersionVO);
			com.tansun.easycare.rule.common.FileUtils.writeFileDrl(flowVersion.getRuleContent().getBytes(), drlBasePath+"/func_"+projectCode+".drl");
		}
		//复制配置文件jar meta目录 包括固定的maven信息等
		File srcDir = new File(URLDecoder.decode(this.getClass().getResource("/").getPath()+"/rulePackageMeta", "UTF-8"));
		File destDir = new File(deploypath+File.separator+"packageDir");
		FileUtils.copyDirectory(srcDir, destDir);
		
		
		//生成bomMapping 文件
		
		RuleDataset  dataSetInfo  = new  RuleDataset();
		dataSetInfo.setProjectcode(projectCode);
		List<RuleDataset> list =this.ruleDatasetDao.findList(dataSetInfo);
		DataModel  dm  = null;
		Attribute attr = null;
		
		for (RuleDataset ruleDataset :list){
			dm = new  DataModel();
			BeanUtils.copyProperties(dm,ruleDataset);
			RuleDataparams  dataparams  = new  RuleDataparams();
			dataparams.setDatasetId(ruleDataset.getId());
			List<RuleDataparams> paraList = this.ruleDataparamsService.findList(dataparams);
			for (RuleDataparams ruleDataparams: paraList){
				attr  = new  Attribute();
				BeanUtils.copyProperties(attr, ruleDataparams);
				dm.getAttrList().add(attr);
			}
			xmlTool.writeXml(dm, deploypath+File.separator+"packageDir"+Constant.DMFILE,Constant.DATEFORMAT,"id","class");
			
		}
		
		JavaUnmarshaller.bom2Xml(deploypath+File.separator+"packageDir"+deployFile, depm, Deployment.class);
//		//压缩包
		ZipUtils.antzip(deploypath+"/packageDir", deploypath+File.separator+"rulePackage.jar", false);
		
		//统计压缩包信息
		//规则打包日志：执行人 执行时间
		//组件类别 名称 文件名 最后修改日期
		//文件个数:
		logStrbuf.append("规则Drl包打包任务完成:"+spf.format(new Date())+" 规则文件共 "+fileCount+" 个\n");
		
		//打jar包
		createRuleJavaPackage(logStrbuf,ruleVersions,deploypath,projectCode,deployment.getEnterPoints());
		
		File packageLogFile = new File(deploypath+"/packageLog.log");
		if(packageLogFile.exists()){
			FileUtils.write(packageLogFile, logStrbuf, "UTF-8", true);
		}else{
			FileUtils.write(packageLogFile, logStrbuf, "UTF-8");
		}
		
	}
	
	public void createRuleJavaPackage(StringBuffer logStrbuf,List<RuleVersionVO> ruleVersions, String deploypath,String projectCode,String invokePoint) throws Exception {

		File packageJarDir = new File(deploypath+"/packageJarDir/");
		if(packageJarDir.exists()){
			//备份历史包信息
			File ruleJarPackageF = new File(deploypath+"/ruleExcuter.jar");
			File bakDir = new File(deploypath+File.separator+"_jar_"+spf2.format(new Date()));
			FileUtils.copyDirectory(packageJarDir, bakDir);
			FileUtils.copyFileToDirectory(ruleJarPackageF, bakDir, true);
			logStrbuf.append("备份历史jar包数据:"+spf.format(new Date())+"\n");
			ruleJarPackageF.delete();
			
			deleteDir(packageJarDir);
		}
		packageJarDir.mkdirs();
		logStrbuf.append("规则Jar包文件列表:\n");
		
/*		RuleJarPackage ruleJarPackage = new RuleJarPackage(projectCode,invokePoint);
		ruleJarPackage.setDeploypath(deploypath+File.separator+RuleJarPackage.DEPOLY_DIR+File.separator);
		ruleJarPackage.setRuleVersions(ruleVersions);
		ruleJarPackage.createJar();
		
		int fileCount = ruleJarPackage.getFileCount();
		
		//统计压缩包信息
		//规则打包日志：执行人 执行时间
		//组件类别 名称 文件名 最后修改日期
		//文件个数:
		logStrbuf.append("规则Jar包打包任务完成:"+spf.format(new Date())+" 规则文件共 "+fileCount+" 个\n");*/
		
	}
	
	/**
	 * 递归删除文件夹
	 * @param dir
	 * @return
	 */
	private static boolean deleteDir(File dir) {
		if (dir.isDirectory()) {
			String[] children = dir.list();
			for (int i = 0; i < children.length; i++) {
				boolean success = deleteDir(new File(dir, children[i]));
				if (!success) {
					return false;
				}
			}
		}
		return dir.delete();
	}
	
	@Override
	public RuleDeployment deployRemoteServer(String id,String  projectCode) throws Exception{
		//String path = Global.getConfig("DeployFileDir") +"/"+projectCode;
		String deployInd = Global.getConfig("Deploy.jar.ind");
		
		RuleDeployment deployment=this.get(id);
		if (deployInd != null && "0".equals(deployInd)){
			RuleEnterpoint  ruleEnterpoint = new RuleEnterpoint();
			ruleEnterpoint.setDeploymentId(id);
			List<RuleEnterpoint> list =this.ruleEnterpointService.findList(ruleEnterpoint);
			String  enterPonit ="";
			String  tmpStr ="";		
			deployment.setStatusInd("1");
			this.save(deployment);
			for (int i =0;i<list.size();i++){
				tmpStr  = list.get(i).getCode();
				if (i>0)
					tmpStr =";"+tmpStr;
				enterPonit = enterPonit+tmpStr;
			}
			deployment.setEnterPoints(enterPonit);
			return deployment;
		}
/*		String packagePath = path+modelDir+"/"+deployment.getDeployCode()+"/rulePackage.jar";
		String result = HttpUtils.deployRulePackage(deployment.getServerUrl()+"/deploy/depolyRuleJar.do", packagePath,
				deployment.getUserName(), deployment.getPassword(),"", projectCode);
		System.out.println("result======="+result);*/
		return deployment;
	}
	
	@SuppressWarnings("resource")
	@Override
	public String runRemoteDeploy(RuleDeployment deployment) throws Exception{
		HttpClient httpclient = new DefaultHttpClient();  
		HttpPost post = new HttpPost(deployment.getServerUrl()+ Global.getConfig("RuleDeploySpark"));  

		List<NameValuePair> pairs = new ArrayList<NameValuePair>();  
		 
		NameValuePair pair1 = new BasicNameValuePair("userName", deployment.getUserName());  
		NameValuePair pair2 = new BasicNameValuePair("password", deployment.getPassword());  
		NameValuePair pair3 = new BasicNameValuePair("ruleObjectName", deployment.getProjectCode());  
		NameValuePair pair4 = new BasicNameValuePair("invokePoint", deployment.getEnterPoints());  
		NameValuePair pair5 = new BasicNameValuePair("deployCode", "");
		NameValuePair pair6 = new BasicNameValuePair("serverType", "Stom"); 
		NameValuePair pair7 = new BasicNameValuePair("fileName", deployment.getFileName()); 
           
		pairs.add(pair1);  
		pairs.add(pair2);  
		pairs.add(pair3); 
		pairs.add(pair4);
		pairs.add(pair5);
		pairs.add(pair6);
		pairs.add(pair7);
		
		post.setEntity(new UrlEncodedFormEntity(pairs,HTTP.UTF_8));  
		HttpResponse response = httpclient.execute(post);
		String result = "";
		if(HttpStatus.SC_OK==response.getStatusLine().getStatusCode()){    
			HttpEntity entitys = response.getEntity();  
			if (entitys != null) {  
				result=EntityUtils.toString(entitys);
			}
		}else{
			result = response.toString();
		}
		return result;
    }

	@Override
	public int setReflactData(RuleDeployment deployment,ReflactDataVO reflactDataVO) throws Exception{
		String url = deployment.getServerUrl()+Global.getConfig("RuleSetReflactData");
    	String enterPoint = deployment.getEnterPoints();
		CloseableHttpClient httpClient = HttpClients.createDefault();
		
		HttpPost httpPost = new HttpPost(url);// 创建httpPost 
		reflactDataVO.setEnterPoint(enterPoint);
		reflactDataVO.setDeploymentId(deployment.getId());
		String json = JSON.toJSONString(reflactDataVO);
		StringEntity requestEntity = new StringEntity(json,"utf-8");
        requestEntity.setContentEncoding("UTF-8");    	        
        httpPost.setHeader("Content-type", "application/json");
		httpPost.setEntity(requestEntity);
		
		HttpResponse response = httpClient.execute(httpPost);
		int state = response.getStatusLine().getStatusCode();
		return state;
	}
	/**
	 * 获取规则数据、将数据发布到规则执行业务系统存储
	 */
	public RuleDataInfo getRulePackageData(String projectCode,String deployCode) throws Exception {
		RuleDataInfo ruleDataInfo = new RuleDataInfo();
		RuleDeployment deployment = this.get(deployCode);//1.发布信息
		ruleDataInfo.setDeployment(deployment);
		RuleEnterpoint  enterInfo  = new  RuleEnterpoint();
		enterInfo.setDeploymentId(deployment.getId());
		List<RuleEnterpoint> enterPoints =  this.ruleEnterpointService.findList(enterInfo) ;//2.发步规则对应入口点信息
		ruleDataInfo.setEnterPoints(enterPoints);
		List<RuleVersioninfo> flowVersions = new ArrayList<RuleVersioninfo>();//3.规则信息
		List<RuleReferenceData> refList = new ArrayList<RuleReferenceData>();
		for (RuleEnterpoint enterPoint : enterPoints) {
//			String[] ruleflowinfo = enterPoint.getRuleflowId().split("_");
//			List<RuleVersioninfo> tmp =this.ruleFlowService.findRuleFlowPublishVersion(projectCode,ruleflowinfo[0], ruleflowinfo[1]);
			RuleManage rulemanage = ruleManageService.findByCode(enterPoint.getRuleflowId(), projectCode);
//			String[] ruleflowinfo = enterPoint.getRuleflowId().split("_");
			List<RuleVersioninfo> tmp =this.ruleFlowService.findRuleFlowPublishVersion(projectCode,enterPoint.getRuleflowId(), rulemanage.getActiveVersion());
			for (RuleVersioninfo ruleVersioninfo : tmp) {
				ruleVersioninfo.setEnterPointer(enterPoint.getCode());
				//查找该入口点规则流对应的入参
				RuleReferenceData condition = new RuleReferenceData();
				condition.setProjectCode(projectCode);
				condition.setManageId(ruleVersioninfo.getManageId());
				condition.setVersion(ruleVersioninfo.getVersion());
				List<RuleReferenceData> tmpList = ruleReferenceDataService.findList(condition);
				for (RuleReferenceData ruleReferenceData : tmpList) {
					ruleReferenceData.setEnterPointer(enterPoint.getCode());
				}
				refList.addAll(tmpList);
				flowVersions.add(ruleVersioninfo.copyBean());
			}
		}
		ruleDataInfo.setRefList(refList);
		
		//决策树关联引用模型
		List<RuleVersioninfo> verList=  this.ruleVersioninfoService.findProjectRefeList(projectCode);
		for (RuleVersioninfo ruleVersioninfo : verList) {
			ruleVersioninfo.setRefModelStatus("1");
		}
//		ruleDataInfo.setRefModelList(verList);
		flowVersions.addAll(verList);
		
		RuleVersioninfo  verInfo  = new  RuleVersioninfo();
		verInfo.setProjectCode(projectCode);
		verInfo.setManageId("func_"+projectCode);
		List<RuleVersioninfo> flist =this.ruleVersioninfoService.findList(verInfo);
		if (flist != null && flist.size()>0){
			flowVersions.add(flist.get(0));
		}
		ruleDataInfo.setFlowVersions(flowVersions);
		//生成bomMapping 文件
		RuleDataset  dataSetInfo  = new  RuleDataset();
		dataSetInfo.setProjectcode(projectCode);
		List<RuleDataset> dataSetlist =this.ruleDatasetDao.findList(dataSetInfo);//4.数据集信息
		ruleDataInfo.setDataSetlist(dataSetlist);
		List<RuleDataparams> paraList = new ArrayList<>();//5.变量信息
		DataModel  dm  = null;
		for (RuleDataset ruleDataset :dataSetlist){
			dm = new  DataModel();
			BeanUtils.copyProperties(dm,ruleDataset);
			RuleDataparams  dataparams  = new  RuleDataparams();
			dataparams.setDatasetId(ruleDataset.getId());
			List<RuleDataparams> tmp = this.ruleDataparamsService.findList(dataparams);
			paraList.addAll(tmp);
		}
		ruleDataInfo.setParaList(paraList);
		return ruleDataInfo;
	}

	@Override
	public int updateStatusIndById(List<String> deploymentIds) {
		return ruleDeploymentDao.updateStatusIndById(deploymentIds);
	}
	
	/**
	 * 同步执行库数据
	 * @param projectCode
	 * @throws Exception
	 */
	@Override
	public void synchExeTable(String id,String projectCode) throws Exception {
		List<com.tansun.ruledata.entity.RuleDataInfo> ruledatainfoList = new ArrayList<com.tansun.ruledata.entity.RuleDataInfo>();
    	RuleDataInfo ruleDataInfo = getRulePackageData(projectCode,id);
    	ruledatainfoList.add(ruleDataInfo.changeClass());
    	bussinessSynchService.synchRuleData(ruledatainfoList, projectCode);
	}
}
